package com.card.controller.system;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.card.entity.system.Customer;
import com.card.result.Result;
import com.card.service.system.SystemService;
import com.card.util.ValidUtil;
import com.card.vo.CardVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * ClassName: SystemController <br/>
 * Function: 系统资源录入. <br/>
 * date: 2018年12月14日 上午8:48:49 <br/>
 * 
 * @author lishuai11
 * @version
 * @since JDK 1.8
 */
@Api(value = "导入卡数据")
@RestController
@RequestMapping("/sys/")
public class SystemController {

	@Autowired
	private SystemService systemService;

	@ApiOperation(value = "导入客户", httpMethod = "POST", notes = "办卡客户信息")
	@RequestMapping(value = "card/customer", method = RequestMethod.POST)
	public Result cardCustomer(
			@RequestBody @ApiParam(name = "customers", value = "客户信息list") List<Customer> customers) {
		if (customers == null || customers.isEmpty()) {
			return Result.fail(Result.CLIENT_ERROR, "请传入客户信息");
		}
		for (Customer customer : customers) {
			List<String> list = ValidUtil.validate(customer);
			if (list != null && !list.isEmpty()) {
				StringBuilder errorString = new StringBuilder();
				list.forEach(row -> {
					errorString.append(row).append(";");
				});
				return Result.fail(Result.CLIENT_ERROR, errorString.toString());
			}
		}
		return systemService.postCustomer(customers);
	}

	@ApiOperation(value = "银行卡积分列表", httpMethod = "GET", notes = "银行卡与积分对应关系表", response = CardVo.class, responseContainer = "list")
	@RequestMapping(value = "cards", method = RequestMethod.GET)
	public Result cards() {
		return systemService.cards();
	}

}
